<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="orgCode">
      <el-input v-model="dataForm.orgCode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orgName">
      <el-input v-model="dataForm.orgName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orgabbr">
      <el-input v-model="dataForm.orgabbr" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="bankId">
      <el-input v-model="dataForm.bankId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orgType">
      <el-input v-model="dataForm.orgType" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orgLevel">
      <el-input v-model="dataForm.orgLevel" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="parent">
      <el-input v-model="dataForm.parent" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="attechorg">
      <el-input v-model="dataForm.attechorg" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="txproxy">
      <el-input v-model="dataForm.txproxy" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="presproxy">
      <el-input v-model="dataForm.presproxy" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="acptproxy">
      <el-input v-model="dataForm.acptproxy" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="svclist">
      <el-input v-model="dataForm.svclist" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="region">
      <el-input v-model="dataForm.region" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="linkman">
      <el-input v-model="dataForm.linkman" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="phone">
      <el-input v-model="dataForm.phone" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="state">
      <el-input v-model="dataForm.state" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="exchflag">
      <el-input v-model="dataForm.exchflag" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="exchregion">
      <el-input v-model="dataForm.exchregion" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="enabledate">
      <el-input v-model="dataForm.enabledate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="disabledate">
      <el-input v-model="dataForm.disabledate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="lastupdate">
      <el-input v-model="dataForm.lastupdate" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="exchroute">
      <el-input v-model="dataForm.exchroute" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          orgId: 0,
          orgCode: '',
          orgName: '',
          orgabbr: '',
          bankId: '',
          orgType: '',
          orgLevel: '',
          parent: '',
          attechorg: '',
          txproxy: '',
          presproxy: '',
          acptproxy: '',
          svclist: '',
          region: '',
          linkman: '',
          phone: '',
          state: '',
          exchflag: '',
          exchregion: '',
          enabledate: '',
          disabledate: '',
          lastupdate: '',
          exchroute: ''
        },
        dataRule: {
          orgCode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orgName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orgabbr: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          bankId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orgType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orgLevel: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          parent: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          attechorg: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          txproxy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          presproxy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          acptproxy: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          svclist: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          linkman: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          exchflag: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          exchregion: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          enabledate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          disabledate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          lastupdate: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          exchroute: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.orgId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orgId) {
            this.$http({
              url: this.$http.adornUrl(`/sys/organinfo/info/${this.dataForm.orgId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === '0000') {
                this.dataForm.orgCode = data.result.orgCode
                this.dataForm.orgName = data.result.orgName
                this.dataForm.orgabbr = data.result.orgabbr
                this.dataForm.bankId = data.result.bankId
                this.dataForm.orgType = data.result.orgType
                this.dataForm.orgLevel = data.result.orgLevel
                this.dataForm.parent = data.result.parent
                this.dataForm.attechorg = data.result.attechorg
                this.dataForm.txproxy = data.result.txproxy
                this.dataForm.presproxy = data.result.presproxy
                this.dataForm.acptproxy = data.result.acptproxy
                this.dataForm.svclist = data.result.svclist
                this.dataForm.region = data.result.region
                this.dataForm.linkman = data.result.linkman
                this.dataForm.phone = data.result.phone
                this.dataForm.state = data.result.state
                this.dataForm.exchflag = data.result.exchflag
                this.dataForm.exchregion = data.result.exchregion
                this.dataForm.enabledate = data.result.enabledate
                this.dataForm.disabledate = data.result.disabledate
                this.dataForm.lastupdate = data.result.lastupdate
                this.dataForm.exchroute = data.result.exchroute
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sys/organinfo/${!this.dataForm.orgId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'orgId': this.dataForm.orgId || undefined,
                'orgCode': this.dataForm.orgCode,
                'orgName': this.dataForm.orgName,
                'orgabbr': this.dataForm.orgabbr,
                'bankId': this.dataForm.bankId,
                'orgType': this.dataForm.orgType,
                'orgLevel': this.dataForm.orgLevel,
                'parent': this.dataForm.parent,
                'attechorg': this.dataForm.attechorg,
                'txproxy': this.dataForm.txproxy,
                'presproxy': this.dataForm.presproxy,
                'acptproxy': this.dataForm.acptproxy,
                'svclist': this.dataForm.svclist,
                'region': this.dataForm.region,
                'linkman': this.dataForm.linkman,
                'phone': this.dataForm.phone,
                'state': this.dataForm.state,
                'exchflag': this.dataForm.exchflag,
                'exchregion': this.dataForm.exchregion,
                'enabledate': this.dataForm.enabledate,
                'disabledate': this.dataForm.disabledate,
                'lastupdate': this.dataForm.lastupdate,
                'exchroute': this.dataForm.exchroute
              })
            }).then(({data}) => {
              if (data && data.code === '0000') {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
